package cn.actoncode.boot.module.ai.controller.app.user;

import cn.actoncode.boot.framework.common.pojo.CommonResult;
import cn.actoncode.boot.framework.security.core.annotations.PreAuthenticated;
import cn.actoncode.boot.framework.web.core.util.WebFrameworkUtils;
import cn.actoncode.boot.module.ai.controller.app.user.vo.AppUserInfoRespVO;
import cn.actoncode.boot.module.ai.convert.user.MemberUserConvert;
import cn.actoncode.boot.module.ai.dal.dataobject.user.MemberUserDO;
import cn.actoncode.boot.module.ai.service.user.MemberUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.actoncode.boot.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 API")
@RestController
@RequestMapping("/user")
@Validated
@Slf4j
public class AppUserController {

    @Resource
    private MemberUserService memberUserService;

    @GetMapping("/info")
    @Operation(summary = "获取用户信息")
    @PreAuthenticated
    public CommonResult<AppUserInfoRespVO> getUserInfo() {
        Long userId = WebFrameworkUtils.getLoginUserId();
        MemberUserDO user = memberUserService.getUserByUserId(userId);
        AppUserInfoRespVO respVO = MemberUserConvert.INSTANCE.convert05(user);
        return success(respVO);
    }
}

